<?php
$db = new Database;
$auth = Auth::getAuth('current_user');
$user_id = $auth['id'];
$company_id = $auth['company_id'];
?>
    <div class="drag" style="position: fixed;left: 0;bottom: 0;top:0;z-index:1000;margin-top:2px;margin: 32px 0px 0px 0px;border-right: 1px solid #ddd; width: 30px; min-height: 100%;background-color: #fff;">
        <?php
        $userAvatarMessage = $db->query("SELECT * FROM tbuser WHERE online='1' and id!='$user_id' and company_id ='$company_id'","array");
        foreach($userAvatarMessage as $imageData){
            $name = $imageData['firstname'].'-'.$imageData['lastname'];
            echo "<a href=\"javascript:void(0)\" onclick=\"javascript:chatWith('".$imageData['firstname']."')\">";
            //echo "<a class='openChat'>";
        echo myAvatar($imageData['extension'],$imageData['id'],"30","30","border:1px solid #ddd;");
            echo "</a>";
            //echo '</a>';
        }
        ?>
    </div>
    <?php if($auth['steps']=="0"){?>
    <div id="modalBox" style="display: none; position: fixed; opacity: 1; z-index: 11000; left: 50%; margin-left: -330px; top: 100px;">
    </div>
    <div id="modalBg" style="display: none; opacity: 0.5;"></div>
    <!-- Help File For the steps -->
    <div class="checklistStep" style="z-index: -10000;position: fixed;right: 0;bottom: 0;top:0;margin: 32px 0px 0px 0px;border-left: 1px solid #ddd; width: 190px; min-height: 100%;overflow: auto;background-color: #fff;">
        <span class="fontGray">Procedures for Step 3</span>
        <div class="hr"></div>
        <a rel="modalBg" name="test" href="#modalBox" class="helpFileForSteps" data-steps="step3" data-action="helpStep3">
            <span class="fontGray">&nbsp;View Help?</span>
        </a>
                <ul>
                    
                        <li class="step3-1 step3" style="padding: 5px;border-bottom: 1px solid #ddd;">
                            3.1. On the 3rd step, if you have any user  or you as the admin, you need to specify what group do you want
                            to belong to remove user/you on the list.
                        </li>
                    
                    <li class="step3-2 step3" style="padding: 5px;border-bottom: 1px solid #ddd;">
                        3.2. Click <icon class="icon-edit"></icon> icon to change the group of the selected user.
                    </li>
                    <li class="step3-3 step3" style="padding: 5px;border-bottom: 1px solid #ddd;">
                        3.3. Delete selected user by clicking the <icon class="icon-trash"></icon> icon.
                    </li>
                    <li class="step3-4 step3" style="padding: 5px;border-bottom: 1px solid #ddd;">
                        3.4.  If your done to assign a group for your user just click step 4 to proceed to the next step.
                    </li>
                </ul>
    </div>
    <?php
    }
    if($auth['steps']=="0"){
        // Redirect to the next step if it is done
        $fStep = $db->query("SELECT * FROM tborgchart WHERE company_id='$company_id'","numrows");
        if($fStep!=0&&$auth['steps']!="0"){
            echo '<meta http-equiv="refresh" content="0;url=/formalistic/org_chart">';
        }
    }
    
    ?>
    <div class="body_contents">
        <?php if($auth['steps']=="0"){?>
        <div style="text-align: center;">
            <a href="/formalistic/org_chart"><img src="/images/steps/step1.png" style="cursor:pointer;"/></a>
            <a href="/formalistic/administer"><img src="/images/steps/step2.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/user_management"><img src="/images/steps/step3A.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/administer?step=4"><img src="/images/steps/step4.png" style="margin-left: -30px; cursor:pointer;"/></a>
            <a href="/formalistic/forms"><img src="/images/steps/step5.png" style="margin-left: -30px; cursor:pointer;"/></a>
        </div>
        <?php } ?>
        <?php if($auth['steps']!="0"){ ?>
        <!-- Registration Request -->
        <div class="titleBar">
            <div class="left">
               <div class="titlePosition">
                    <div style="float: right;margin-top: -3px;"><img src="/images/icon/minus.png" class="pull-left plusBox cursor" id="accordion1" data-dropping="accordion1"></div>
                    <div style="float: left;margin-top: 2px;">Registration Request</div>
               </div>
            </div>
            <div class="right align_right">
            </div>
         </div>
        <div class="Holdercontent accordion1">
            <div class="top">
                <div id="registrationRequest_tbl"></div>
            </div>
            <div class="down">
               
            </div>
        </div>
        <!-- User List -->
        <div class="titleBar">
            <div class="left">
               <div class="titlePosition">
                    <div style="float: right;margin-top: -3px;"><img src="/images/icon/plus.png" class="pull-left plusBox cursor" id="accordion2" data-dropping="accordion2"></div>
                    <div style="float: left;margin-top: 2px;">User List</div>
               </div>
            </div>
            <div class="right align_right">
                
            </div>
         </div>
        <div class="Holdercontent accordion2 display">
            <div class="top">
                <div id="userList_tbl"></div>
            </div>
            <div class="down">
               
            </div>
        </div>
        <?php } ?>
        <!-- Floating Accounts-->
        <div class="titleBar">
            <div class="left">
               <div class="titlePosition">
                    <div style="float: right;margin-top: -3px;"><img src="/images/icon/<?php if($auth['steps']!="0"){echo 'plus';}else{echo 'minus';}?>.png" class="pull-left plusBox cursor" id="accordion3" data-dropping="accordion3"></div>
                    <div style="float: left;margin-top: 2px;">Floating Accounts</div>
               </div>
            </div>
            <div class="right align_right">
            </div>
         </div>
        <div class="Holdercontent accordion3 <?php if($auth['steps']!="0"){echo 'display';}?>">
            <div class="top">
                <!--div id="floatingAcct_tbl"></div-->
                <?php
                $getFloatingUsers = $db->query("SELECT * FROM tbuser where status = 1 and company_id = '$company_id' and is_active = 1 and position_id!=0","array");
                ?>
                <table class="table_data floating_accounts">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Floating Group</th>
                            <th colspan="2">Action</th>
                        </tr>
                    </thead>
                    <tbody class="accountsDelBody">
                        <?php
                        $ctr = 0;
                        foreach($getFloatingUsers as $setFloatingUsers){
                            $getActiveRole = $db->query("SELECT * from tborgchart o LEFT JOIN tborgchartobjects oo on o.id=oo.orgChart_id where o.status=1 and o.company_id = $company_id and oo.role='".$setFloatingUsers['role']."'","row");
                            if($setFloatingUsers['role']!=$getActiveRole['role']){
                                ?>
                                <tr id="userFloatList_<?php echo $setFloatingUsers['id']; ?>">
                                    <td style="text-align:center"><?php echo setName($setFloatingUsers['firstname'],$setFloatingUsers['middlename'],$setFloatingUsers['lastname']); ?></td>
                                    <td style="text-align:center">
                                    <span class="spanRole" id="spanRole_<?php echo $setFloatingUsers['id'];?>"><?php echo $setFloatingUsers['role'];?></span>
                                    <?php
                                    $userRole = $setFloatingUsers['role'];
                                    $activate = $db->query("SELECT * from tborgchart where status = '1' and company_id = '$company_id'","row");
                                    $diagram_id = $activate['id'];
                                    $selectRole = $db->query("SELECT role from tborgchartobjects where orgChart_id = '$diagram_id'","array");
                                    ?>
                                    <select class="input-xlarge userRoleEdit" id='userRoleEdit_<?php echo $setFloatingUsers['id']; ?>' style="display: none">
                                        <?php
                                        foreach($selectRole as $dataRole){
                                            ?>
                                            <option <?php echo setSelected($userRole,$dataRole['role']); ?>  value="<?php echo $dataRole['role']; ?>"><?php echo $dataRole['role']; ?></option>
                                            <?php
                                        }
                                        foreach($selectTableRole as $dataTableRole){
                                            ?>
                                            <option <?php echo setSelected($userRole,$dataTableRole['role']); ?> value="<?php echo $dataTableRole['role']; ?>"><?php echo $dataTableRole['role']; ?></option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                    </td>
                                    <td style="text-align:center">
                                        <a class="icon-edit actionUser editFloatingUser" rel="editFloatingUser" style="cursor: pointer" id="editFloatingUser_<?php echo $setFloatingUsers['id']; ?>" title="Update Account"></a>
                                        <a class="icon-ok actionUser saveEditFloatingUser"  rel="saveEditFloatingUser" style="cursor: pointer;display: none;margin-right: 5px" id="saveEditFloatingUser_<?php echo $setFloatingUsers['id']; ?>" title="Save Account"></a>
                                        <a class="icon-remove actionUser cancelFloatingEditUser" rel="cancelEditUser" style="cursor: pointer;display: none" id="cancelEditUser_<?php echo $setFloatingUsers['id']; ?>" title="Cancel Update"></a>
                                    </td>
                                    <td style="text-align:center"><a class="icon-trash actionUser" rel="deactivateUser" style="cursor: pointer" id="<?php echo $setFloatingUsers['id']; ?>" title="Deactivate"></a></td>
                                </tr>
                                <?php
                                $ctr++;
                            }
                        }
                        if($ctr==0){
                            ?>
                            <tr>
                                <td colspan="5"  style="text-align:center">No Record Found</td>
                            </tr>
                            <?php
                        }
                            ?>
                    </tbody>
                </table>
            </div>
            <div class="down">
               
            </div>
        </div>
        <?php if($auth['steps']!="0"){ ?>
        <!-- Deleted Accounts -->
        <div class="titleBar">
            <div class="left">
               <div class="titlePosition">
                    <div style="float: right;margin-top: -3px;"><img src="/images/icon/plus.png" class="pull-left plusBox cursor" id="accordion4" data-dropping="accordion4"></div>
                    <div style="float: left;margin-top: 2px;">Disabled Accounts</div>
               </div>
            </div>
            <div class="right align_right">
            </div>
         </div>
        <div class="Holdercontent accordion4 display">
            <div class="top">
                <div id="DeletedAcc_tbl"></div>
            </div>
            <div class="down">
               
            </div>
        </div>
        <?php } ?>
    </div>
    <script>
        setActivNav("administer");
    </script>